# -*- coding: utf-8 -*-
"""
Module Description:
Date: 2019/3/18
Author: chenmurong
"""
from pyshare.utils.time_utils import getCT, isPassDay
from pyshare.const.enums.payment import UnlockType


class QueenJewelryMiXin(object):

    activity_id = NotImplemented
    role_guid = NotImplemented
    cur_score = NotImplemented
    cheat_stat = NotImplemented
    grid_data = NotImplemented
    last_restart_time = NotImplemented
    vit_buy_count = NotImplemented
    merge_record_list = NotImplemented
    merge_award_stat = NotImplemented

    @property
    def is_expire_data(self):
        """是否是过期数据（没有重置，一直停留在二级界面可能导致没有重置）"""
        if isPassDay(self.last_restart_time):
            return True
        return False

    def refresh_queen_jewelry(self, is_restart=False):
        """
        隔天重置或者重玩
        :param is_restart:
        :return:
        """
        from pyshare.dal.repository_impl import QueenJewelryRoleRecordRepository
        from app.area.component.queen_jewelry.queen_jewelry_component import QueenJewelryActivityComponent

        if not isPassDay(self.last_restart_time) and not is_restart:
            # 隔天重置，判断是否隔天
            return

        self.cur_score = 0
        self.cheat_stat = {}
        self.grid_data = QueenJewelryActivityComponent.init_grid_data()
        self.last_restart_time = getCT()
        if is_restart:
            # 重玩重置数据到这里结束
            self.merge_record_list = {key: [val[0], 0] for key, val in self.merge_record_list.items()}
            QueenJewelryRoleRecordRepository.save(self)
            return

        self.vit_buy_count = 0
        self.merge_record_list = {}
        self.merge_award_stat = []
        QueenJewelryRoleRecordRepository.save(self)

    @property
    def is_unlock_special_award(self):
        """
        特殊奖励是否解锁
        :return:
        """
        from app.area.component.recharge_unlock_component import RechargeUnlockComponent
        result = RechargeUnlockComponent.check_has_recharge_unlock(self.role_guid,
                                                                   UnlockType.QueenJewelrySpecialAward,
                                                                   self.activity_id)
        return 1 if result else 0
